<!doctype html>
<html>
<head>
	<meta charset="utf-8">
	<title>我的</title>
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
	<link href="../css/mui.css" rel="stylesheet"/>
	<link href="../css/mui.min.css" rel="stylesheet"/>
	<link href="../css/mui-icons-extra.css" rel="stylesheet"/>
	<link href="../css/app.css" rel="stylesheet"/>
	<style type="text/css">
		.hr {
			width: 100%;
			height: 20px;
			background: #F0F0F0;
			border: 0;
		}
	</style>
</head>
<body>
	<!-- 头部TITLE -->
	<div class="app-my">
		<div class="app-my-bg">
			<img src="../imgs/tmp2.png" id="uHeadBg">
		</div>
		<table class="app-my-title">
			<tr>
				<td class="app-title-img">
					<!-- <img src="http://tsh.fuzhuangchangongxiao.cn/uploads/20200314/2020031421480916.jpg"> -->
					<img src="../imgs/tmp2.png" id="uHead" 
						onclick="setUpload()">
				</td>
				<td>
					<div class="app-signature">
					<b id="uname">昵称</b>
					<p id="udetail">个人签名</p>
				</td>
				<td>
					<div class="app-my-set app-heart-blue" 
						onclick="jumpToMyset()">
						<b>设置</b>
						<span class="mui-icon mui-icon-gear"></span>
					</div>
				</td>
			</tr>
		</table>
	</div>
	<!-- <textarea id="path"></textarea> -->
	<!-- 头部TITLE -->
	
	<!-- 主体部分 -->
	<!-- 点赞/收藏/创单 -->
	<ul class="mui-table-view">
		<li class="mui-table-view-cell" 
			onclick="jumpToMyZanList()">
			<a class="mui-navigate-right">
				我的点赞
				<span class="mui-icon-extra mui-icon-extra-heart-filled app-heart-light"></span>
				<span class="app-list-right">
					<p class="app-heart-light" id="zanTotal">0</p>
				</span>
			</a>
		</li>
		<li class="mui-table-view-cell" 
			onclick="jumpToMyCollectList()">
			<a class="mui-navigate-right">
				我的收藏
				<span class="mui-icon mui-icon-starhalf app-heart-light"></span>
				<span class="app-list-right">
					<p class="app-heart-light" id="collectTotal">0</p>
				</span>
			</a>
		</li>
<!-- 		<li class="mui-table-view-cell" 
			onclick="jumpToMySignList()">
			<a class="mui-navigate-right">
				我的签到
				<span class="mui-icon mui-icon-location app-heart-light"></span>
				<span class="app-list-right">
					<p class="app-heart-light" id="signTotal">0</p>
				</span>
			</a>
		</li> -->
	</ul>
	<!-- 点赞/收藏/创单 -->
	<!-- 空行 -->
	<div class="hr"></div>
	<!-- 空行 -->
	<!-- 创作过程 -->
	<ul class="mui-table-view">
		<li class="mui-table-view-cell" 
			onclick="jumpToMyPlusList()">
			<a class="mui-navigate-right">
				加入创单
				<span class="mui-icon mui-icon-plus app-heart-light"></span>
				<span class="app-list-right">
					<p class="app-heart-light" id="plusTotal">0</p>
				</span>
			</a>
		</li>
		<li class="mui-table-view-cell">
			<a class="mui-navigate-right">
				 我的创板
				 <span class="mui-icon mui-icon-pengyouquan app-heart-light"></span>
			</a>
		</li>
		<li class="mui-table-view-cell">
			<a class="mui-navigate-right">
				 我的作品
				 <span class="mui-icon-extra mui-icon-extra-cart app-heart-light"></span>
			</a>
		</li>
	</ul>
	<!-- 创作过程 -->
	<!-- 空行 -->
	<div class="hr"></div>
	<!-- 空行 -->
	<!-- 我的财务 -->
	<ul class="mui-table-view">
		<li class="mui-table-view-cell">
			<a class="mui-navigate-right">
				 我的金币
				 <span class="mui-icon-extra mui-icon-extra-gold app-heart-light"></span>
			</a>
		</li>
	</ul>
	<!-- 我的财务 -->
	<!-- 空行 -->
	<div class="hr"></div>
	<!-- 空行 -->
	<!-- 我的财务 -->
	<!-- 关于应用 -->
	<ul class="mui-table-view">
		<li class="mui-table-view-cell" onclick="setSign()">
			<a class="mui-navigate-right">
				 我的签到
				 <span class="mui-icon mui-icon-location app-heart-light"></span>
			</a>
		</li>
		<li class="mui-table-view-cell" 
			onclick="jumpToMyOpinionList()">
			<a class="mui-navigate-right">
				 有奖建议
				 <span class="mui-icon mui-icon-compose app-heart-light"></span>
			</a>
		</li>
		<li class="mui-table-view-cell" onclick="jumpToMyHelp()">
			<a class="mui-navigate-right">
				 使用帮助
				 <span class="mui-icon mui-icon-help app-heart-light"></span>
			</a>
		</li>
	</ul>
	<!-- 关于应用 -->
	<!-- 空行 -->
	<div class="hr"></div>
	<!-- <textarea rows="5" id="pathUrl"></textarea> -->
	<!-- <div class="hr"></div> -->
	<br><br><br>
	<!-- 空行 -->
	<!-- 主体部分 -->
	
	<!-- 底部菜单 -->
	<nav class="mui-bar mui-bar-tab">
		<a class="mui-tab-item" onclick="jumpToIndex()">
			<span class="mui-icon mui-icon-home"></span>
			<span class="mui-tab-label">首页</span>
		</a>
		<a class="mui-tab-item" onclick="jumpToMarket()">
			<span class="mui-icon mui-icon-download"></span>
			<span class="mui-tab-label">库</span>
		</a>
<!-- 		<a class="mui-tab-item" onclick="jumpToMarket()">
			<span class="mui-icon mui-icon-download"></span>
			<span class="mui-tab-label">广场</span>
		</a> -->
<!-- 		<a class="mui-tab-item" onclick="jumpToCamera()">
			<span class="mui-icon mui-icon-camera"></span>
			<span class="mui-tab-label">拍</span>
		</a> -->
<!-- 		<a class="mui-tab-item" onclick="jumpToChat()">
			<span class="mui-icon mui-icon-chatbubble"></span>
			<span class="mui-tab-label">消息</span>
		</a> -->
		<a class="mui-tab-item mui-active" onclick="jumpToMy()">
			<span class="mui-icon mui-icon-contact"></span>
			<span class="mui-tab-label">我的</span>
		</a>
	</nav>
</body>
</html>

<script src="../js/mui.js"></script>
<script src="../js/app.js"></script>
<script src="../js/upload.js"></script>
<script type="text/javascript">
	// 上传头像图片
	function setUpload(){
		// 系统参数
		var sys = getSys();
		var uploadDomain = sys.domain + '/app/user/head/tmp';
		var modifyDomain = sys.domain + '/app/user/head/modify';
		// 上传参数
		var configs = {
			selector:'uHead',
			uploadUrl:uploadDomain,
			modifyUrl:modifyDomain
		};
		choosePhoto(configs);
	}
	//自动加载
	(function($, owner) {
		// 用户信息
		getUserInfo();
		// 统计
		getTotal();
	}(mui, window.app = {}));
	// 获取用户信息
	function getUserInfo(){
		// 判断用户登陆
		var userInfo = cacheGet(userInfoKey);
		if (!userInfo) {
			mui.toast('没有登陆',{ 
				duration:'short', type:'div',
			});
			setTimeout(function(){
				jumpToMyLogin();
			}, 500);
			return
		}
		// mui.alert(userInfo.head);
		// 用户信息
		var uname = getStrLimitNum(userInfo.name, 10);
		var udetail = getStrLimitNum(userInfo.detail, 10);
		mui("#uname")[0].innerHTML = uname;
		mui("#udetail")[0].innerHTML = udetail;
		if (userInfo.head!='') {
			// mui.alert(userInfo.head);
			document.getElementById('uHead').src = userInfo.head;
		}
	}
	// 获取点赞/收藏统计
	function getTotal(){
		// mui("#zanTotal")[0].innerHTML = cache.list.length;
		var indexList = getIndexCache();
		var marketList = getMarketCache();
		var resIndex = indexList.list;
		var resMarket = marketList.list;
		var zanTotal = 0;
		var collectTotal = 0;
		var plusTotal = 0;
		// mui.toast('??'+resIndex[0].zanTotal)
		if (resIndex.length > 0) {
			for (var i=0;i<resIndex.length;i++) {
				zanTotal = zanTotal * 1 + resIndex[i].zanTotal;
				collectTotal = collectTotal * 1 + resIndex[i].collectTotal;
			}
		}
		if (resMarket.length > 0) {
			for (var m=0;m<resMarket.length;m++) {
				zanTotal = zanTotal * 1 + resMarket[m].zanTotal;
				collectTotal = collectTotal * 1 + resMarket[m].collectTotal;
				plusTotal = plusTotal * 1 + resMarket[m].plusTotal;
			}
		}
		mui("#zanTotal")[0].innerHTML = zanTotal;
		mui("#collectTotal")[0].innerHTML = collectTotal;
		mui("#plusTotal")[0].innerHTML = plusTotal;
	}
	//获取首页数据缓存
	function getIndexCache(){
		var resList = cacheGet(indexList);
		if (!resList) {
			var list = new Array(),  //数据数组
				idstring = ''; //ID字符串集合
			return {
				// 数据数组
				list: list,
				// 历史ID集合
				idstr: idstring
			};
		}
		return resList;
	}
	//获取库数据缓存
	function getMarketCache(){
		var resList = cacheGet(marketList);
		if (!resList) {
			var list = new Array(),  //数据数组
				idstring = ''; //ID字符串集合
			return {
				// 数据数组
				list: list,
				// 历史ID集合
				idstr: idstring
			};
		}
		return resList;
	}
	////////////////图片处理////////////////
	// // mui.init();
	// // document.getElementById("uHead").addEventListener("tap", function() {
	// function choosePhoto() {
	// 	// mui.plusReady(function () {
	// 		plus.nativeUI.actionSheet(
	// 			{
	// 				// title: '修改头像',
	// 				cancel: '取消',
	// 				buttons: [
	// 					{ title: '拍照' }, 
	// 					{ title: '从手机相册选择' },
	// 				],
	// 			}, function(e) {
	// 				switch (e.index) {
	// 					case 0:
	// 						break;
	// 					case 1: //拍照 
	// 						appendByCamera();
	// 						break;
	// 					case 2: //打开相册  
	// 						appendByGallery();
	// 						break;
	// 					default:
	// 						break;
	// 				}
	// 			}, 
	// 		false);
	// 	// });
	// }
	// // });
	// // 拍照添加文件
	// function appendByCamera(){
	// 	plus.camera.getCamera().captureImage(function(e){
	// 		plus.io.resolveLocalFileSystemURL(e, function(entry) { 
	// 		var path = entry.toLocalURL(); 
	// 		document.getElementById("uHead").src = path; 
	// 		}, function(e) { 
	// 			mui.toast("读取拍照文件错误："+e.message); 
	// 		}); 
	// 	});    
	// }
	// // 从相册添加文件
	// function appendByGallery(){
	// 	plus.gallery.pick(function(path){
	// 		// 更新头像地址
	// 		// mui("#pathUrl")[0].innerHTML = path; 
	// 		document.getElementById('uHead').src = path;
	// 		setUploadFileTmp();
	// 	});
	// }
	// // 上传文件
	// function setUploadFileTmp(){
	// 	// 系统参数
	// 	var sys = getSys();
	// 	var domain = sys.domain + '/app/user/head/tmp';
	// 	// 域名+参数
	// 	var method = {
	// 		method:"POST", 
	// 		blocksize:204800, 
	// 		priority:100
	// 	};
	// 	var file = document.getElementById('uHead').src;
	// 	// 生成时间戳+随机值
	// 	var randString = '0';
	// 	for (var i=0;i<4;i++) {
	// 	    randString += Math.floor(Math.random()*10);
	// 	}
	// 	var stamp = Date.parse(new Date())+randString
	// 	// mui.toast(uid); return
	// 	var task = plus.uploader.createUpload(
	// 		domain, method,
	// 		function(t,status){ //上传完成
	// 			if(status==200){
	// 				// mui.alert("上传成功："+t.responseText);
	// 				// mui.toast("上传成功："+t.responseText);
	// 				var resData = JSON.parse(t.responseText);
	// 				resData = resData.data;
	// 				var filePath = resData.filePath;
	// 				// mui.alert("上传成功："+filePath);
	// 				// document.getElementById('uHead').src = filePath;
	// 				// 更新用户缓存
	// 				setUserInfoHead(filePath);
	// 				// 更新服务器头像信息
	// 				setUploadFileUpdate(stamp);
	// 			}else{
	// 				// mui.alert("上传失败："+status);
	// 				mui.toast("上传失败："+status);
	// 			}
	// 		}
	// 	);
	// 	//添加其他参数
	// 	task.addData("stamp",stamp);
	// 	task.addFile(file,{ key:"file" });
	// 	task.start();
	// }  
	// // 更新文件信息
	// function setUploadFileUpdate(stamp){
	// 	// 系统参数
	// 	var sys = getSys();
	// 	var domain = sys.domain + '/app/user/head/modify';
	// 	// 用户信息
	// 	var userInfo = cacheGet(userInfoKey);
	// 	var userId = userInfo ? userInfo.uid : 0;
	// 	// mui.toast(stamp); return
	// 	mui.ajax(sys.domain+'/app/user/head/modify',{
	// 		data:{
	// 			// appAccess: sys.appAccess,
	// 			uid:userId,
	// 			stamp:stamp
	// 		},
	// 		dataType:'json', //服务器返回json格式数据
	// 		type:'post', //HTTP请求类型
	// 		timeout:10000, //超时时间设置为10秒
	// 		headers:{'Content-Type':'application/x-www-form-urlencoded'}, 
	// 		success:function(res){
	// 			mui.alert('res：'+res.data.url); return 
	// 			// if (res.code!=0) {
	// 			// 	// mui.toast('上传失败');
	// 			// 	return
	// 			// }
	// 			// mui.toast('OK')
	// 		},
	// 		error:function(xhr,type,errorThrown){
	// 			mui.toast('网络错误！',{ 
	// 				duration:'short', type:'div',
	// 			});
	// 		}
	// 	});
	// }
	// // 更新用户缓存
	// function setUserInfoHead(headPath){
	// 	// 用户信息
	// 	var userInfo = cacheGet(userInfoKey);
	// 	userInfo.head = headPath;
	// 	cacheSet(userInfoKey, userInfo);
	// }
	////////////////图片处理////////////////
	
	// 定位测试
	function setSign(){
		mui.plusReady(function() {
			plus.geolocation.getCurrentPosition(translatePoint,function(e){
				mui.toast("异常:" + e.message);
	        });
		});
	}
	 function translatePoint(position){
	    var currentLon = position.coords.longitude;
	    var currentLat = position.coords.latitude;
	    mui.toast(currentLon);
		//书写自己的逻辑
	}
</script>